<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>获取本地媒体</title>
  <style>
    video {
      width: 640px;
      height: 480px;
      border: 1px solid black;
    }

    div {
      display: inline-block;
    }
  </style>
</head>

<body>
  <script src="https://webrtc.github.io/adapter/adapter.js" type="text/javascript"></script>
  <script>
    var myVideo;
    window.onload = function() {
      myVideo = document.getElementById('myVideo')
      getMedia()
    } 
    function getMedia() {
      (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia)({'audio': true, 'video': true}, gotUserMedia, didntGetUserMedia)
    }

    function gotUserMedia(stream) {
      myVideo.srcObject = stream
    }

    function didntGetUserMedia() {
      console.log('could not get video')
    }
  </script>

  <div style="width:30%;vertical-align:top">
    <div>
      <video id="myVideo" autoplay="autoplay" controls muted="true"/>
    </div>
  </div>
</body>

</html>